home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / p4.h < prev    next >
Text File  |  1993-12-06  |  4KB  |  122 lines

  1. /**
  2.  ** P4.H
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifdef __TURBOC__
  25. # pragma  inline
  26. #endif
  27.  
  28. #include "grx.h"
  29. #include "libgrx.h"
  30. #include "vgaregs.h"
  31.  
  32. #ifdef __TURBOC__
  33.   typedef unsigned char far *pixptr;
  34. #endif
  35.  
  36. #ifdef __GNUC__
  37.   typedef unsigned char volatile *pixptr;
  38. #endif
  39.  
  40. #define C_SIGNIF        0x0f    /* significant bits in a color */
  41.  
  42. #define P_OFFSET(off)        ((int)(off) & 0x07)
  43. #define P_XPOS(off)        (((unsigned)COORD_X(off)) >> 3)
  44. #define P_ADDRESS(cxt,off)  ((pixptr)((cxt)->gc_baseaddr +        \
  45.     (unsigned)(COORD_Y(off) * (cxt)->gc_lineoffset) +            \
  46.     P_XPOS(off)                                \
  47. ))
  48.  
  49. extern int  _GrP4ModeReg;        /* saved bits of mode register */
  50. extern int  _GrP4WriteOps[4];        /* VGA write ops (Set, Xor...) */
  51. extern int  _GrP4DrawTable[4];        /* drawing enable table */
  52.  
  53.  
  54. /*
  55.  * compute left and right masks for fills and bitblt
  56.  */
  57. #define _ComputeMasks(adr,wdt,lmsk,rmsk) do {                \
  58.     register int _temp_;                        \
  59.     lmsk = rmsk = 0;                            \
  60.     if((_temp_ = P_OFFSET((int)adr + wdt)) != 0) {            \
  61.     wdt -= _temp_;                            \
  62.     rmsk = (unsigned char)(0xff00 >> _temp_);            \
  63.     }                                    \
  64.     if((_temp_ = P_OFFSET(adr)) != 0) {                    \
  65.     wdt -= (8 - _temp_);                        \
  66.     lmsk = (0xff >> _temp_);                    \
  67.     }                                    \
  68.     if((wdt >>= 3) < 0) {                        \
  69.     lmsk &= rmsk;                            \
  70.     rmsk = 0;                            \
  71.     wdt  = 0;                            \
  72.     }                                    \
  73. } while(0)
  74.  
  75. /*
  76.  * left and right mask bytes in an integer...
  77.  */
  78. #define L_MASK(_word_)        (((unsigned char *)(&(_word_)))[0])
  79. #define R_MASK(_word_)        (((unsigned char *)(&(_word_)))[1])
  80. #define _ComputeMaskWord(addr,wdt,mword) do {                \
  81.     _ComputeMasks(addr,wdt,L_MASK(mword),R_MASK(mword))            \
  82. } while(0)
  83.  
  84. #ifdef  __GNUC__
  85. #define _GetVGAModeMask() do {                        \
  86.     if(_GrAdapterType == GR_VGA) asm volatile(                 "\n\
  87.     movl    $L_VGA_GR_CTRL_PORT,%%edx                  \n\
  88.     movb    $L_VGA_MODE_REG,%%al                      \n\
  89.     outb    %%al,%%dx                          \n\
  90.     incl    %%edx                              \n\
  91.     inb    %%dx,%%al                          \n\
  92.     movb    %%al,%%ah                          \n\
  93.     andb    $0xfc,%%ah                          \n\
  94.     movb    $L_VGA_MODE_REG,%%al                      \n\
  95.     movl    %%eax,%0                           "\
  96.     : "=g" (_GrP4ModeReg)                        \
  97.     : /* NOTHING */                            \
  98.     : "dx", "ax"                            \
  99.     );                                    \
  100.     else { /* EGA */                            \
  101.     _GrP4ModeReg = VGA_MODE_REG;                    \
  102.     }                                    \
  103. } while(0)
  104. #endif
  105.  
  106. #ifdef  __TURBOC__
  107. #define _GetVGAModeMask() do {                        \
  108.     if(_GrAdapterType == GR_VGA) {                    \
  109.     asm mov        dx,VGA_GR_CTRL_PORT;                \
  110.     asm mov        al,VGA_MODE_REG;                    \
  111.     asm out        dx,al;                        \
  112.     asm inc        dx;                            \
  113.     asm in        al,dx;                        \
  114.     _GrP4ModeReg = ((_AX & 0xfc) << 8) | VGA_MODE_REG;        \
  115.     }                                    \
  116.     else { /* EGA */                            \
  117.     _GrP4ModeReg = VGA_MODE_REG;                    \
  118.     }                                    \
  119. } while(0)
  120. #endif
  121.  
  122.